#ifndef __BASE_SOCKET_H_
#define __BASE_SOCKET_H_
#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <string>
#include <string.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <netdb.h>
#include <netinet/tcp.h>
#include <netinet/in.h>
#include <poll.h>
#include <inttypes.h>
#include <stdint.h>

namespace BASE{
class Socket{
	public:
		Socket();

		virtual ~Socket();

		int write(const void * data, int len);

		int read(void *data, int len);

		bool isConnected(int millsecs = 5000);

		bool setAddress(const char * address, const int port);

		bool checkSocketHandle();

		bool connect();

		bool connectTimeout(int millsecs = 500);

		void close();

		void shutdown();

		bool setReuseAddress(bool  on);

		bool setSoLinger(bool doLinger, int seconds);

		bool setTcpNoDelay(bool noDelay);

		bool setBlocking(bool block);

		void getIpAndPort(std::string & ip, uint16_t & port);

		uint64_t getId();

		static int getLastError(){
			return errno;
		}
	protected:
		struct sockaddr_in _address;
		int socketHandle;
		bool _connected;
	};

}
#endif
